package life.fairy.community.controller;

import life.fairy.community.dto.PaginationDTO;
import life.fairy.community.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class IndexController {

    @Autowired
    private QuestionService questionService;

    @GetMapping("/")
    public String index(
            Model model,
            @RequestParam(name = "page", defaultValue = "1") Integer page, // 获取的参数 显示的page
            @RequestParam(name = "size", defaultValue = "10") Integer size  // 获取的参数 每一页显示的数据量
    ) {

        PaginationDTO pagination = questionService.list(page, size);// 通过中间层 pagination 进行返回到html页面数据的封装
        model.addAttribute("pagination", pagination);
        return "index";
    }

}
